<template>
  <div class="row">
    <div class="col-4" v-for="column in columnList" :key="column.id">
      <div class="card h-100">
        <img :src="column.avatar" :alt="column.title" class="card-img-top h-50" >
        <div class="card-body">
          <h5>{{ column.title }}</h5>
            <p>{{ column.description }}</p>
          <a href="#" class="btn btn-primary">进入专栏</a>
        </div>
      </div>
    </div>
  </div>
</template>

<script lang="ts">
import { computed, defineComponent, PropType } from 'vue'
export interface ColumnProps {
  id: number;
  title: string;
  avatar?: string;
  description: string;
}
export default defineComponent({
  name: 'ColumnList',
  props: {
    list: {
      type: Array as PropType<ColumnProps[]>,
      required: true
    }
  },
  setup (props) {
    const columnList = computed(() => {
      return props.list.map(column => {
        if (!column.avatar) {
          column.avatar = require('@/assets/logo.png')
        }
        return column
      })
    })
    return { columnList }
  }
})
</script>

<style>
</style>
